//
//  CellWithButtonCtrl.m
//  Review-Objective-C
//
//  Created by mac on 2017/7/21.
//  Copyright © 2017年 com.qiankun. All rights reserved.
//

#import "CellWithButtonCtrl.h"
#import "BTNCell.h"

@interface CellWithButtonCtrl ()
<UITableViewDelegate,UITableViewDataSource,BTNCellDelegate>

@property(nonatomic,strong) UITableView *tableView;

@end

@implementation CellWithButtonCtrl

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setNicePatch];
    
//    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 400, 500)];
//    _tableView.dataSource = self;
//    [self.view addSubview:_tableView];
//    
    
}

//添加九宫格
-(void)setNicePatch{
   
    int cols = 3;
    CGFloat viewW = 80;
    CGFloat viewH = 90;
    
    CGFloat margin = (KScreenBounds.size.width - cols * viewW) / (cols + 1);
    int count = 12;
    
    for (int i = 0; i<count; i++) {
        int row = i /cols;
        int col = i % cols;
        CGFloat viewX = margin + (margin + viewW) *col;
        CGFloat viewY = margin + (margin + viewH) *row;
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(viewX, viewY, viewW, viewH)];

        [v setBackgroundColor:[UIColor redColor]];
        
        [self.view addSubview:v];
        
    }
    
    
    
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 20;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BTNCell *cell = [[BTNCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    
    if (!cell) {
         cell = [[BTNCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    cell.BTNCellDelegate = self;
    
    if (indexPath.row % 2 == 0) {
        cell.backgroundColor = [UIColor orangeColor];
    }else{
        cell.backgroundColor = [UIColor grayColor];
    }
    return cell;
}

-(void)selectBtn:(UIButton *)btn{
    NSLog(@"url ceho ");
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
